<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>省市县三级级联</title>
  <script type="text/javascript" src="provincesdata.js" ></script>
  <script type="text/javascript">
	//alert("省级单位："+GP.length);
	//onload窗口加载事件
	window.onload = function(){	
		var str = "<select onchange='loadCity(this.value)'>";
		for(var i=0;i<GP.length;i++){
			str+="<option value='"+i+"'>"+GP[i]+"</option>";
		}
		str+="</select>";
		document.getElementById("provinceNode").innerHTML = str;
	}
	//通过省编号加载地级市
	function loadCity(pid){
		//alert("省id："+pid);
		var str = "<select onchange='loadCountry("+pid+",this.value)'>";
		for(var i=0;i<GT[pid].length;i++){
			str+="<option value='"+i+"'>"+GT[pid][i]+"</option>";
		}
		str+="</select>";
		document.getElementById("cityNode").innerHTML = str;
	}

	//通过省编码和市编号，加载区县
	function loadCountry(pid,cid){
		var str = "<select >";
		for(var i=0;i<GC[pid][cid].length;i++){
			str+="<option value='"+i+"'>"+GC[pid][cid][i]+"</option>";
		}
		str+="</select>";
		document.getElementById("countryNode").innerHTML = str;
	}
  </script>  
 </head>
 <body>
	<span id="provinceNode"></span>
	<span id="cityNode"></span>
	<span id="countryNode"></span>
 </body>
</html>
